﻿Imports System.Drawing

Public Class Block
    Inherits DoubleRectangle
    Implements IDisposable

    Public bufferedImage As Bitmap

    Public Sub New(pt As Point, sz As Size, sprite As Bitmap, id As Tile.TileID)
        MyBase.New(pt, sz)
        Me.bufferedImage = sprite
        Me.ID = id
        Me.Init()
    End Sub

    Property ID As Tile.TileID = Tile.TileID.Air

    Public Sub Init()

    End Sub

    Public Sub Render(g As Graphics)
        g.DrawImage(bufferedImage, New Point(Me.Location.X * Tile.TileSize, Me.Location.Y * Tile.TileSize))
        'g.DrawImage(bufferedImage, New Point(Me.Location.X, Me.Location.Y))
    End Sub

#Region "IDisposable Support"
    Private disposedValue As Boolean = False ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: dispose managed state (managed objects).
                If (Not IsNothing(bufferedImage)) Then
                    bufferedImage.Dispose()
                    bufferedImage = Nothing
                End If

            End If

            ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
            ' TODO: set large fields to null.
        End If
        Me.disposedValue = True
    End Sub

    ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
    Protected Overrides Sub Finalize()
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(False)
        MyBase.Finalize()
    End Sub

    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class
